package com.lwl.service.impl.sds;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lwl.entity.MyPage;
import com.lwl.entity.sds.TSdsCallback;
import com.lwl.entity.Tuser;
import com.lwl.service.sds.TSdsCallbackService;
import com.lwl.dao.sds.TSdsCallbackMapper;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpSession;
import java.util.Date;
import java.util.List;

/**
 * (TSdsCallback)表服务实现类
 *
 * @author Lei
 * @since 2022-11-10 12:31:59
 */
@Service
public class TSdsCallbackServiceImpl implements TSdsCallbackService {
   @Autowired
   private TSdsCallbackMapper tSdsCallbackDao;

   @Override
   public PageInfo queryAll(MyPage myPage, TSdsCallback tSdsCallback) {
      PageHelper.startPage(myPage.getPage(),myPage.getLimit());
      List<TSdsCallback> tSdsCallbackList = tSdsCallbackDao.selectAll();
      PageInfo pageInfo = new PageInfo<>(tSdsCallbackList);
      return pageInfo;
   }

   @Override
   public int insertCallback(TSdsCallback tSdsCallback, HttpSession session) {
      int insert = -1;
      if (tSdsCallback.getId()==null){
         tSdsCallback.setCreatetime(new Date());
         insert = tSdsCallbackDao.insert(tSdsCallback);
      }else {
         tSdsCallback.setUpdatetime(new Date());
         Tuser user = (Tuser)session.getAttribute("user");
         String username = user.getUsername();
         tSdsCallback.setUpdateby(username);
         insert = tSdsCallbackDao.updateByPrimaryKeySelective(tSdsCallback);
      }
      return insert;
   }
}
